package ywpt.service.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.stereotype.Service;

import ywpt.core.dao.HibernateEntityDao;
import ywpt.model.ClientInfo;
import ywpt.model.JobInfo;
import ywpt.model.PeopleInfo;
import ywpt.model.RepairInfo;
import ywpt.model.SmallAmount;
import ywpt.service.work.SysMsgInfoService;
@Service("smallAmountService")
public class SmallAmountServiceImpl extends HibernateEntityDao<SmallAmount> implements SmallAmountService{

	private SysMsgInfoService sysMsgInfoService;
	
	public SysMsgInfoService getSysMsgInfoService() {
		return sysMsgInfoService;
	}

	public void setSysMsgInfoService(SysMsgInfoService sysMsgInfoService) {
		this.sysMsgInfoService = sysMsgInfoService;
	}

	@Override
	public SmallAmount getSmallAmountById(Long id) {
		return this.get(id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<SmallAmount> getSmallAmounts(DetachedCriteria query,
			int pageSize, int startIndex) {
		return this.findAllByCriteria(query, pageSize, startIndex);
	}

	@Override
	public int getSmallAmountsCountByCriteria(DetachedCriteria query) {
		return this.getCountByCriteria(query);
	}

	@Override
	public void saveSmallAmount(SmallAmount smallAmount, Long jobId, Long repairId, Long clientId, Long checkId) {
		if (jobId!=null) {
			smallAmount.setJobInfo(this.get(JobInfo.class, jobId));
		}
		if (repairId!=null) {
			smallAmount.setRepairInfo(this.get(RepairInfo.class, repairId));
		}
		if (clientId!=null) {
			smallAmount.setClientInfo(this.get(ClientInfo.class, clientId));
		}
		if (checkId!=null) {
			smallAmount.setChecker(this.get(PeopleInfo.class, checkId));
		}
		this.save(smallAmount);
	}

	@Override
	public void updateSmallAmount(SmallAmount smallAmount, Long jobId, Long repairId, Long clientId, Long checkId) {
		if (jobId!=null) {
			smallAmount.setJobInfo(this.get(JobInfo.class, jobId));
		}
		if (repairId!=null) {
			smallAmount.setRepairInfo(this.get(RepairInfo.class, repairId));
		}
		if (clientId!=null) {
			smallAmount.setClientInfo(this.get(ClientInfo.class, clientId));
		}
		if (checkId!=null) {
			smallAmount.setChecker(this.get(PeopleInfo.class, checkId));
		}		
		this.update(smallAmount);		
	}	
	
}
